#include "LogicSession.h"
#include "DBServer.h"
LogicSession::LogicSession()
{
	m_sockFd = INVALID_SOCKET;
}

LogicSession::~LogicSession()
{
}

void LogicSession::OnConnectEvent(const ServiceInfo& _service)
{
	if (m_sockFd != INVALID_SOCKET)
		return;
	m_sockFd = _service.sockFd;
	LogPrint(LogType::WAR, "recv remote connect~");
}

void LogicSession::OnDisConnectEvent(const size_t& _sessionId)
{
	if (m_sockFd == INVALID_SOCKET)
		return;

	LogPrint(LogType::ERR, "remote service disconncet~");
	m_sessionId = 0;
	m_recv.reset();
}


void LogicSession::GetAllSockFd(std::vector<std::pair<SOCKET, size_t>>& _out)
{
	_out.clear();
	if (m_sockFd == INVALID_SOCKET)
		return;
	if (m_sockFd != INVALID_SOCKET)
	{
		_out.emplace_back(m_sockFd, m_sessionId);
	}
}

void LogicSession::OnReadNetData(const size_t& _sessionId)
{
	if (m_sockFd == INVALID_SOCKET)
		return;

	auto result = DBServer::GetInstance()->GetThreadPool().Exec(
		std::bind(&LogicSession::NetPackRead, this, std::placeholders::_1, std::placeholders::_2),
		m_sockFd,
		m_sessionId
	);
	result.wait();
	result.get();
}

void LogicSession::OnWriteNetData(const size_t& _sessionId)
{
}

void LogicSession::OnSocketFdError(const size_t& _sessionId)
{
}

void LogicSession::PostNetPack(NetPackArray& _netPack)
{
}

int32_t LogicSession::NetPackRead(const SOCKET& _fd, const size_t& _sessionId)
{
	return int32_t();
}

int32_t LogicSession::NetPackSend(const SOCKET& _fd, const size_t& _sessionId)
{
	return int32_t();
}
